package com.xrui.hbase.schema.desc;


import com.google.common.base.Preconditions;
import com.xrui.hbase.schema.RowKeyFormat;


import java.util.ArrayList;
import java.util.List;

public class TableLayoutDesc {
    private String name;
    private String description;
    private RowKeyFormat rowKey;
    private List<ColumnDesc> columns = new ArrayList<>();

    public RowKeyFormat getRowKey() {
        return rowKey;
    }

    public void setRowKey(RowKeyFormat rowKeyFormat) {
        this.rowKey = rowKeyFormat;
    }

    public List<ColumnDesc> getColumns() {
        return columns;
    }

    public void setColumns(List<ColumnDesc> columns) {
        this.columns = columns;
    }

    public RowKeyFormat getKeysFormat() {
        return rowKey;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public TableLayoutBuilder newBuilder() {
        return TableLayoutBuilder.newBuilder();
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static class TableLayoutBuilder {
        private String mName;
        private RowKeyFormat mRowKey;
        private List<ColumnDesc> mColumns = new ArrayList<>();


        public static TableLayoutBuilder newBuilder() {
            return new TableLayoutBuilder();
        }

        public TableLayoutBuilder withTableName(String name) {
            mName = name;
            return this;
        }

        public TableLayoutBuilder withRowKey(RowKeyFormat rowKey) {
            mRowKey = rowKey;
            return this;
        }

        public TableLayoutBuilder withColumns(List<ColumnDesc> columns) {
            mColumns = columns;
            return this;
        }

        public TableLayoutBuilder addColumn(ColumnDesc column) {
            mColumns.add(column);
            return this;
        }

        public TableLayoutDesc build() {
            Preconditions.checkNotNull(mName);
            Preconditions.checkNotNull(mRowKey);
            Preconditions.checkArgument(!mColumns.isEmpty());
            TableLayoutDesc layoutDesc = new TableLayoutDesc();
            layoutDesc.setName(mName);
            layoutDesc.setRowKey(mRowKey);
            layoutDesc.setColumns(mColumns);
            return layoutDesc;
        }
    }
}
